home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Strings / ConstPString.cp < prev    next >
Text File  |  1997-06-28  |  1KB  |  63 lines

  1. // ConstPString.cp
  2.  
  3. #ifndef ConstPString_h
  4. #include "ConstPString.h"
  5. #endif
  6. #ifndef MinMax_h
  7. #include "MinMax.h"
  8. #endif
  9.  
  10. bool operator==( ConstPString a, ConstPString b )
  11.   {
  12.     if ( a.Length() != b.Length() )
  13.         return false;
  14.     
  15.     for ( uint32 i = 0; i < a.Length(); i++ )
  16.         if ( a[i] != b[i] )
  17.             return false;
  18.     
  19.     return true;
  20.   }
  21.  
  22. bool operator<( ConstPString a, ConstPString b )
  23.   {
  24.     uint32 matched = Min( a.Length(), b.Length() );
  25.     
  26.     for ( uint32 i = 0; i < matched; i++ )
  27.         if ( a[i] < b[i] )
  28.             return true;
  29.     
  30.     return a.Length() < b.Length();
  31.   }
  32.  
  33. bool operator<=( ConstPString a, ConstPString b )
  34.   {
  35.     uint32 matched = Min( a.Length(), b.Length() );
  36.     
  37.     for ( uint32 i = 0; i < matched; i++ )
  38.         if ( a[i] > b[i] )
  39.             return false;
  40.     
  41.     return a.Length() <= b.Length();
  42.   }
  43.  
  44. int32 Compare( ConstPString a, ConstPString b )
  45.   {
  46.     uint32 matched = Min( a.Length(), b.Length() );
  47.     
  48.     for ( uint32 i = 0; i < matched; i++ )
  49.       {
  50.         int32 comparison = int32(a[i]) - int32(b[i]);
  51.         if ( comparison != 0 )
  52.             return comparison;
  53.       }
  54.     
  55.     if ( a.Length() > b.Length() )
  56.         return 1;
  57.     
  58.     if ( a.Length() < b.Length() )
  59.         return -1;
  60.     
  61.     return 0;
  62.   }
  63.